package com.ruoyi.course.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.domain.LabCourseTimetable;
import com.ruoyi.course.service.ILabCourseTimetableService;

/**
 * 课程时间Controller
 * 
 * @author jun.wang
 * @date 2022-04-05
 */
@RestController
@RequestMapping("/course/timetable")
public class LabCourseTimetableController extends BaseController {
	@Autowired
	private ILabCourseTimetableService labCourseTimetableService;

	/**
	 * 查询课程时间列表
	 */
	@PreAuthorize("@ss.hasPermi('course:timetable:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabCourseTimetable labCourseTimetable) {
		startPage();
		List<LabCourseTimetable> list = labCourseTimetableService.selectLabCourseTimetableList(labCourseTimetable);
		return getDataTable(list);
	}

	/**
	 * 导出课程时间列表
	 */
	// @PreAuthorize("@ss.hasPermi('course:timetable:export')")
	/*
	 * @Log(title = "课程时间", businessType = BusinessType.EXPORT)
	 * 
	 * @GetMapping("/export") public AjaxResult export(LabCourseTimetable
	 * labCourseTimetable) { List<LabCourseTimetable> list =
	 * labCourseTimetableService.selectLabCourseTimetableList(labCourseTimetable
	 * ); ExcelUtil<LabCourseTimetable> util = new
	 * ExcelUtil<LabCourseTimetable>(LabCourseTimetable.class); return
	 * util.exportExcel(list, "timetable"); }
	 */

	/**
	 * 获取课程时间详细信息
	 */
	@PreAuthorize("@ss.hasPermi('course:timetable:query')")
	@GetMapping(value = "/{timetableId}")
	public AjaxResult getInfo(@PathVariable("timetableId") Long timetableId) {
		return AjaxResult.success(labCourseTimetableService.selectLabCourseTimetableById(timetableId));
	}

	/**
	 * 新增课程时间
	 */
	@PreAuthorize("@ss.hasPermi('course:timetable:edit')")
	@Log(title = "课程时间", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabCourseTimetable labCourseTimetable) {
		return toAjax(labCourseTimetableService.insertLabCourseTimetable(labCourseTimetable));
	}

	/**
	 * 修改课程时间
	 */
	@PreAuthorize("@ss.hasPermi('course:timetable:edit')")
	@Log(title = "课程时间", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabCourseTimetable labCourseTimetable) {
		return toAjax(labCourseTimetableService.updateLabCourseTimetable(labCourseTimetable));
	}

	/**
	 * 删除课程时间
	 */
	@PreAuthorize("@ss.hasPermi('course:timetable:edit')")
	@Log(title = "课程时间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{timetableIds}")
	public AjaxResult remove(@PathVariable Long[] timetableIds) {
		return toAjax(labCourseTimetableService.deleteLabCourseTimetableByIds(timetableIds));
	}
}
